package models

import (
	"fmt"

	"gorm.io/driver/mysql"
	"gorm.io/gorm"

	"2106a-zg5/demo/goods/goods_srv/config"
	"2106a-zg5/demo/goods/goods_srv/utils"
)

var DB *gorm.DB

func init() {
	utils.ViperInit()
	dsn := config.GoodsConfig{}.Mysql
	var err error
	DB, err = gorm.Open(mysql.Open(dsn), &gorm.Config{})
	if err != nil {
		fmt.Println(err.Error())
		return
	}
	DB.Debug()
	fmt.Println("Mysql database successfully")
}

type Goods struct {
	Id             int64   `json:"id"`
	GoodsName      string  `json:"goods_name"`
	GoodsPrice     float64 `json:"goods_price"`
	GoodsInventory int64   `json:"goods_inventory"`
	models
}
type models struct {
	CreatedAt string
	UpdatedAt string
	DeletedAt string `gorm:"index"`
}
